home *** CD-ROM | disk | FTP | other *** search
- /*
- * UNIX2DOS.C - Translates files between UNIX and DOS/OS/2
- *
- *
- * PROGRAMMER: Martti Ylikoski
- * CREATED: 24.11.1991
- */
- static char *VERSION = "Version 1.0, Copyright(c) Martti Ylikoski, 1991" ;
- /*
- */
-
- #include <stdio.h>
- #include <fcntl.h>
- #include <io.h>
- #include <errno.h>
- #include <param.h>
- #include <paramstd.h>
-
- static char *progname ;
-
- extern unsigned long pflags ;
-
- ParamEntry pentry[12] = {
- "P", &ParamSetPause, 0,
- "F", &ParamSetFold, 0,
- "V", &ParamSetVerbose, 0,
- "R", &ParamSetReport, 0,
- "S", &ParamSetSubDirs, 0,
- "?", &ParamSetHelp, 1,
- "H", &ParamSetHelp, 1,
- "NOD", &ParamSetNoDefault, 0,
- "TEST", &ParamSetTest, 0,
- "Y", &ParamSetYes, 0,
- "N", &ParamSetTest, 0,
- "\0", NULL, 0
- } ;
-
- ParamBlock params = {
- "/-", IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
- pentry
- } ;
-
-
- main(int argc, char *argv[])
- {
- FILE *fpin, *fpout ;
- char buf[1024] ;
- progname = argv[0] ;
-
- ParamHandle(¶ms, &argc, argv) ;
-
- if (pflags & PA_HELP)
- {
- printf("%s - Translates files between UNIX and DOS/OS/2.\n", progname) ;
- puts(VERSION) ;
- puts("Usage: UNIX2DOS [file1 [file2]] [/? | /H]") ;
- puts("Where,") ;
- puts(" /H,/? = Help") ;
- puts("If file1 is missing, UNIX2DOS reads from the standard input") ;
- puts("if file2 is missing, UNIX2DOS writes to the standard output") ;
- return( 0 ) ;
- }
-
- if (argc == 1)
- {
- setmode(0, O_BINARY) ;
- fpin = stdin ;
- }
- else
- {
- if ((fpin = fopen(argv[1], "rb")) == NULL)
- {
- fprintf(stderr, "%s unable to open input file %s\n", progname, argv[1]) ;
- return( 1 ) ;
- }
- }
-
- if (argc < 3)
- fpout = stdout ;
- else
- {
- if ((fpout = fopen(argv[2], "wt")) == NULL)
- {
- fprintf(stderr, "%s unable to open output file %s\n", progname, argv[2]) ;
- fclose(fpin) ;
- return( 1 ) ;
- }
- }
-
- while(fgets(buf, sizeof(buf), fpin) != NULL)
- {
- fputs(buf, fpout) ;
- if (ferror(fpin) || ferror(fpout))
- {
- fprintf(stderr, "%s: error in processing\nFiles may be only partially converted\n", progname) ;
- fclose(fpin) ;
- fclose (fpout) ;
- return( 1 ) ;
- }
- }
-
- fclose(fpin) ;
- fclose(fpout) ;
- return( 0 ) ;
- }
-